import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { BaseinfoProductApi } from '#/api/csyt/baseinfoproduct';

import { DICT_TYPE, getDictOptions } from '#/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'productName',
      label: '产品名称',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入产品名称',
      },
    },
    {
      fieldName: 'productNo',
      label: '产品编号',
      component: 'Input',
      componentProps: {
        placeholder: '请输入产品编号',
      },
    },
    {
      fieldName: 'productPhoto',
      label: '产品封面',
      component: 'ImageUpload',
      componentProps: {
        placeholder: '请输入产品封面',
      },
    },
    {
      fieldName: 'groupId',
      label: '系列ID',
      component: 'Select',
      componentProps: {
        clearable: true,
        options: getDictOptions(
          DICT_TYPE.CSYT_BASEINFO_PRODUCT_GROUP,
          'string',
        ),
        placeholder: '请输入系列ID',
      },
    },
    {
      fieldName: 'type',
      label: '产品类型',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.CSYT_BASEINFO_PRODUCT_TYPE, 'string'),
        placeholder: '请选择产品类型',
      },
    },
    {
      fieldName: 'scope',
      label: '应用领域',
      component: 'Select',
      componentProps: {
        clearable: true,
        options: getDictOptions(
          DICT_TYPE.CSYT_BASEINFO_PRODUCT_SCOPE,
          'string',
        ),
        placeholder: '请选择应用领域',
      },
    },
    {
      fieldName: 'priceType',
      label: '计费类型',
      component: 'Select',
      componentProps: {
        clearable: true,
        options: getDictOptions(
          DICT_TYPE.CSYT_BASEINFO_PRODUCT_PRICE_TYPE,
          'string',
        ),
        placeholder: '请选择计费类型',
      },
    },
    {
      fieldName: 'tags',
      label: '关键词',
      component: 'Select',
      componentProps: {
        clearable: true,
        options: getDictOptions(DICT_TYPE.CSYT_BASEINFO_PRODUCT_TAG, 'string'),
        placeholder: '请选择关键词',
        mode: 'multiple', // 添加这行以启用多选功能
      },
    },
    {
      fieldName: 'productStatus',
      label: '产品状态',
      component: 'Select',
      componentProps: {
        options: getDictOptions(
          DICT_TYPE.CSYT_BASEINFO_PRODUCT_STATUS,
          'string',
        ),
      },
    },
  ];
}

/** 新增/修改的表单状态 */
export function produceStatusFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'productName',
      label: '产品名称',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入产品名称',
      },
    },
    {
      fieldName: 'productNo',
      label: '产品编号',
      component: 'Input',
      componentProps: {
        placeholder: '请输入产品编号',
      },
    },
    {
      fieldName: 'productStatus',
      label: '产品状态',
      component: 'Select',
      componentProps: {
        options: getDictOptions(
          DICT_TYPE.CSYT_BASEINFO_PRODUCT_STATUS,
          'string',
        ),
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'productName',
      label: '产品名称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入产品名称',
      },
    },
    {
      fieldName: 'productNo',
      label: '产品编号',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入产品编号',
      },
    },
    {
      fieldName: 'productPhoto',
      label: '产品封面',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入产品封面',
      },
    },
    {
      fieldName: 'groupId',
      label: '系列ID',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(
          DICT_TYPE.CSYT_BASEINFO_PRODUCT_GROUP,
          'number',
        ),
        placeholder: '请输入系列ID',
      },
    },
    {
      fieldName: 'type',
      label: '产品类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_TYPE.CSYT_BASEINFO_PRODUCT_TYPE, 'number'),
        placeholder: '请选择产品类型',
      },
    },
    {
      fieldName: 'scope',
      label: '应用领域',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入应用领域',
      },
    },
    {
      fieldName: 'priceType',
      label: '计费类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(
          DICT_TYPE.CSYT_BASEINFO_PRODUCT_SCOPE,
          'number',
        ),
        placeholder: '请选择应用领域',
      },
    },
    {
      fieldName: 'tags',
      label: '关键词',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_TYPE.CSYT_BASEINFO_PRODUCT_TAG, 'number'),
        placeholder: '请选择关键词',
        mode: 'multiple', // 启用多选功能
      },
    },
    {
      fieldName: 'productStatus',
      label: '产品状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: [],
        placeholder: '请选择产品状态',
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<BaseinfoProductApi.BaseinfoProduct>['columns'] {
  return [
    { type: 'checkbox', width: 40 },
    {
      field: 'id',
      title: '序号',
      minWidth: 120,
    },
    {
      field: 'productName',
      title: '产品名称',
      minWidth: 120,
    },
    {
      field: 'productNo',
      title: '产品编号',
      minWidth: 120,
    },
    {
      field: 'productPhoto',
      title: '产品封面',
      minWidth: 120,
      cellRender: {
        name: 'CellImage',
      },
    },
    {
      field: 'groupId',
      title: '系列ID',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.CSYT_BASEINFO_PRODUCT_GROUP },
      },
    },
    {
      field: 'type',
      title: '产品类型',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.CSYT_BASEINFO_PRODUCT_TYPE },
      },
    },
    {
      field: 'scope',
      title: '应用领域',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.CSYT_BASEINFO_PRODUCT_TYPE },
      },
    },
    {
      field: 'priceType',
      title: '计费类型',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.CSYT_BASEINFO_PRODUCT_PRICE_TYPE },
      },
    },
    {
      field: 'tags',
      title: '关键词',
      minWidth: 120,
    },
    {
      field: 'productStatus',
      title: '产品状态',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.CSYT_BASEINFO_PRODUCT_STATUS },
      },
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}

// ==================== 子表（标签信息） ====================

/** 新增/修改列表的字段 */
export function useBaseinfoLableinfoGridEditColumns(
  onActionClick?: OnActionClickFn<BaseinfoProductApi.BaseinfoLableinfo>,
): VxeTableGridOptions<BaseinfoProductApi.BaseinfoLableinfo>['columns'] {
  return [
    {
      field: 'lableNo',
      title: '编号',
      minWidth: 120,
      slots: { default: 'lableNo' },
    },
    {
      field: 'lableName',
      title: '标签名称',
      minWidth: 120,
      slots: { default: 'lableName' },
    },
    {
      field: 'lableType',
      title: '标签类型',
      minWidth: 120,
      slots: { default: 'lableType' },
      params: {
        options: [],
      },
    },
    {
      field: 'lableDescription',
      title: '标签描述',
      minWidth: 120,
      slots: { default: 'lableDescription' },
    },
    {
      field: 'lableTemp',
      title: '标签示例',
      minWidth: 120,
      slots: { default: 'lableTemp' },
    },
    // {
    //   field: 'status',
    //   title: '状态',
    //   minWidth: 120,
    //   slots: { default: 'status' },
    //   params: {
    //     options: [],
    //   },
    // },
    // {
    //   field: 'operation',
    //   title: '操作',
    //   minWidth: 180,
    //   align: 'center',
    //   fixed: 'right',
    //   showOverflow: false,
    //   cellRender: {
    //     attrs: {
    //       nameField: 'id',
    //       nameTitle: '指标',
    //       onClick: onActionClick,
    //     },
    //     name: 'CellOperation',
    //     options: [
    //       {
    //         code: 'delete',
    //         show: false,
    //       },
    //     ],
    //   },
    // },
  ];
}

// ==================== 子表（产品信息详情） ====================

/** 新增/修改的表单 */
export function useBaseinfoProductDetailsFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'useType',
      label: '使用方式',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.CSYT_PRODUCT_USE_TYPE),
        placeholder: '请选择使用方式',
      },
    },
    {
      fieldName: 'devUrl',
      label: '测试地址',
      component: 'Input',
      componentProps: {
        placeholder: '请输入测试地址',
      },
    },
    {
      fieldName: 'prodUrl',
      label: '生产地址',
      component: 'Input',
      componentProps: {
        placeholder: '请输入生产地址',
      },
    },
    {
      fieldName: 'useTerms',
      label: '使用条件',
      component: 'Input',
      componentProps: {
        placeholder: '请输入使用条件',
      },
    },
    {
      fieldName: 'updateFrequency',
      label: '更新频率',
      component: 'Input',
      componentProps: {
        placeholder: '请输入更新频率',
      },
    },
    {
      fieldName: 'memory',
      label: '存储大小',
      component: 'Input',
      componentProps: {
        placeholder: '请输入存储大小',
      },
    },
    {
      fieldName: 'increment',
      label: '增量大小',
      component: 'Input',
      componentProps: {
        placeholder: '请输入增量大小',
      },
    },
    {
      fieldName: 'dataDesc',
      label: '数据维度',
      component: 'Input',
      componentProps: {
        placeholder: '请输入数据维度',
      },
    },
    {
      fieldName: 'dataScope',
      label: '数据覆盖范围',
      component: 'Input',
      componentProps: {
        placeholder: '请输入数据覆盖范围',
      },
    },
  ];
}
